cmake_minimum_required(VERSION 3.8)
project(video_recorder)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 查找依赖包
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_transport REQUIRED)
find_package(camera_info_manager REQUIRED)
find_package(OpenCV REQUIRED)

# 包含目录
include_directories(include)

# 添加库目标
add_library(video_recorder_node SHARED
  src/video_recorder_node.cpp
)

# 指定C++标准
target_compile_features(video_recorder_node PUBLIC c_std_99 cxx_std_17)

# 链接依赖库
ament_target_dependencies(video_recorder_node
  rclcpp
  rclcpp_components
  sensor_msgs
  cv_bridge
  image_transport
  camera_info_manager
  OpenCV
)

# 安装头文件
install(DIRECTORY include/
  DESTINATION include
)

# 安装库
install(TARGETS video_recorder_node
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

# 添加可执行文件
add_executable(video_recorder_node_exe src/video_recorder_main.cpp)
target_link_libraries(video_recorder_node_exe video_recorder_node)
set_target_properties(video_recorder_node_exe PROPERTIES OUTPUT_NAME video_recorder_node)

# 安装可执行文件
install(TARGETS video_recorder_node_exe
  DESTINATION lib/${PROJECT_NAME}
)

# 注册组件
rclcpp_components_register_node(
  video_recorder_node
  PLUGIN "video_recorder::VideoRecorderNode"
  EXECUTABLE video_recorder_component
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()